package com.example.demo.controller;

import com.example.demo.service.MyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Jerry.Zeng
 * @version v1.0.0
 * @date 2021/9/28 10:43
 */
@RestController
@RequestMapping("/")
public class Controller {

//    @RequestMapping("/a")
//    public String get() throws InterruptedException {
//        ExecutorService exec = Executors.newCachedThreadPool(new HanlderThreadFactory());
//        exec.execute(()->{
//            System.out.println("1");
//            int i = 1 / 0;
////            throw new CommonException("2222");
//        });
//        return "1";
//    }
//
//    @RequestMapping("/b")
//    public String getq() throws InterruptedException {
//        Thread thread = new Thread(() -> {
//            System.out.println("1");
//            try{
//                int i = 1 / 0;
//            }catch (Exception e){
//                throw new CommonException("2222");
//            }
//        });
//        thread.setUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
//        thread.start();
//        return "1";
//    }


    @Autowired
    private MyService service;

//    @Autowired
//    private MyThreadPoolExecutor aaa;

    @RequestMapping("/c")
    public String getc() throws InterruptedException {

        service.get();
//        try{
//            service.get();
//        }catch (Exception e){
//            System.out.println(e.getMessage());
//        }

//        aaa.execute(() -> {
//            int res = 1 / 0;
//            System.out.println(res);
//        });

//        ThreadPoolExecutor executor = new MyThreadPoolExecutor(5, 5, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<>(10));
////提交执行的任务，不需要关注异常信息的处理
//        executor.execute(() -> {
//            int res = 1 / 0;
//            System.out.println(res);
//        });

        return "1";
    }

}

